//
//  PaperPenViewManager.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/2/24.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperPenViewManager.h"
#import "SketchpadsView.h"
#import "PaperModuleModel.h"

@interface PaperPenViewManager ()

@property (nonatomic, strong) SketchpadsView *view;

@end

@implementation PaperPenViewManager
@dynamic view;

- (void)setupConfigure {
    self.view = [[SketchpadsView alloc] initWithFrame:CGRectMake(0, kStatusBarHeight+4, SCREEN_WIDTH, SCREEN_HEIGHT - kStatusBarHeight-4)];
//    self.view.backgroundColor = [UIColor redColor];
    if (self.superView) {
        [self.superView addSubview:self.view];
    }
    self.view.alpha = 0.0f;
}

- (void)setPenSignal:(RACSignal *)penSignal {
    _penSignal = penSignal;
    
    @weakify(self)
    [[_penSignal map:^id(id value) {
        if ([value isKindOfClass:[PaperAnswerModel class]]) {
            PaperAnswerModel *model = value;
            return [NSNumber numberWithInteger:model.ques_num];
        } else {
            return @(-1);
        }
    }] subscribeNext:^(NSNumber *x) {
        @strongify(self)
        NSInteger index = [x integerValue];
        if (index != -1) {
            [self.view setIndex:index];
            [self.view showWithAnimation:YES];
        }
    }];
}

@end
